package com.xiaoxi.strategymode.play;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.strategymode
 * @ClassName Hand
 * @Description TODO
 * @Date 2023/3/13 20:40
 * @Version 1.0
 */
public class Hand {

    public static final int GUU = 0;    // 石头
    public static final int CHO = 1;    // 剪刀
    public static final int PAA = 2;    // 布

    public static final String[] handsChinese = {
            "石头", "剪刀", "布"
    };

    // 猜拳一共三种情况
    public static final Hand[] hands = {
            new Hand(GUU),
            new Hand(CHO),
            new Hand(PAA)
    };

    private int handValue;

    public Hand(int handValue) {
        this.handValue = handValue;
    }

    // 0-2 给出当前出拳 姿势
    public static Hand getHandValue(int index) {
        return hands[index];
    }

    public boolean isStronger(Hand h) {
        return than(h) == 1;
    }

    public int than(Hand h) {   // 0 平局 1. 胜 -1 负
        if (this.handValue == h.handValue) {
            return 0;
        } else if ((this.handValue + 1) % 3 == h.handValue) {
            return 1;
        } else {
            return -1;
        }
    }

    public String toString() {
        return handsChinese[handValue];
    }
}
